﻿
function getclfftlibrary([string]$filename)
{
    $file = Join-Path $DownloadsPath $filename 

    # download the file (version 2.2 is current at the time of writing)
    $result = $wc.DownloadFile("https://github.com/clMathLibraries/clFFT/releases/download/v2.2/"+$filename,$file)

    # unzip the file
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($file)
    foreach($item in $zip.items())
    {
        $shell.Namespace($DownloadsPath).copyhere($item)
    }

    $folderToCopy = Join-Path $DownloadsPath ([io.path]::GetFileNameWithoutExtension($filename))
    $destFolder = Join-Path $WorkPath "..\FTLibOpenCL"

    # make destination folder (if it does not exists) and copy the extracted files into this
    New-Item -ItemType Directory -Force -Path (Join-Path $destFolder "clFFT")
    Copy-Item $folderToCopy (Join-Path $destFolder "clFFT") -Recurse -Force -Confirm:$False
}

#$local = Get-Location;

# get the path where this script resides
$WorkPath = split-path $MyInvocation.MyCommand.Definition -Parent

# that's the folder where we want to place the downloads and extract the ZIPs
$DownloadsPath = Join-Path $WorkPath "Downloads"

# empty and remove folder if it exists, then create a new one
If (Test-Path $DownloadsPath)
{
    Remove-Item $DownloadsPath -Force -Recurse
}

New-Item -ItemType Directory -Force -Path $DownloadsPath

$wc = New-Object system.Net.WebClient;

getclfftlibrary("clFFT-2.2.0-Windows-x64.zip")
getclfftlibrary("clFFT-2.2.0-Windows-x32.zip")
